<?php
namespace app\common\model;

use think\Model;
use think\Db;
use think\model\concern\SoftDelete;

class TableModel extends Model
{
    use SoftDelete;
    protected $name = 'user_room_table';
    protected $deleteTime = 'delete_time';

    /**
     * 如果牌桌存在则返回牌桌信息
     *
     * @param  [type]  $tid [description]
     * @return boolean      [description]
     */
    public function isExistTable($tid)
    {
        return $this->getById(trim($tid));
    }

    /**
     * 删除牌桌
     *
     * @param  [type] $tid [description]
     * @return [type]      [description]
     */
    public function deleteTable($tid)
    {
        if (!empty($this->get($tid))) {
            return $this->destroy($tid);
        }
        return false;
    }

    /**
     * 数据格式化
     *
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    public function typeDataFormat($data)
    {
        $param = $data;
        $param['innings'] = $this->inningsType($data['innings']);
        $param['number'] = $this->numberType($data['number']);
        return $param;
    }

    /**
     * 局数转换
     *
     * @param  [type] $type [description]
     * @return [type]       [description]
     */
    public function inningsType($type)
    {
        switch ((int)$type) {
            case 0:
                return 4;
                break;

            case 1:
                return 8;
                break;

            case 2:
                return 32;
                break;

            case 3:
                return 64;
                break;
        }
    }

    /**
     * 人数转换
     *
     * @param  [type] $type [description]
     * @return [type]       [description]
     */
    public function numberType($type)
    {
        return (int)$type + 2;
    }

     public function param_format($param = array())
    {
        $param['limit'] = empty($param['limit']) ? 10 : $param['limit'];
        $param['page']  = empty($param['page']) ? 1 : $param['page'];
        $param['id']  = empty($param['id']) ? '' : $param['id'];
        return $param;
    }
}
